package com.zb.code.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.entity.AccounLoginInfo;
import com.zb.result.PageUtil;
import com.zb.result.Result;
import com.zb.service.ZjCodeUserChangeLogService;
import com.zb.service.ZjCodeUserRegisterService;
import com.zb.utils.TokenUtil;
import com.zb.vo.CodeUserChangeLogVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * <p>
 * 编码用户变更记录表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-09-04
 */
@Api(tags = "编码用户变更类接口")
@RestController
@RequestMapping("/code/userChange")
public class ZjCodeUserChangeLogController {
    @Resource
    private ZjCodeUserRegisterService codeUserRegisterService;
    @Resource
    private ZjCodeUserChangeLogService codeUserChangeLogService;

    @SystemLog(moduleType = OperationLogModuleType.CODE_TYPE, remark = "编码档案-编码列表-用户变更 - 保存变更用户")
    @ApiOperation("保存变更用户")
    @PostMapping("/saveChangeCodeUser")
    public Result saveChangeCodeUser(HttpServletRequest request, @RequestBody @Valid CodeUserChangeLogVo changeLogVo) {
        AccounLoginInfo loginInfo = TokenUtil.getAccountLoginInfo(request);
        codeUserRegisterService.saveChangeCodeUser(loginInfo, changeLogVo);
        return Result.success("变更用户成功");
    }

    @ApiOperation("获取变更记录列表")
    @PostMapping("/getList/{codeId}")
    public Result getList(@PathVariable @ApiParam(value = "编码ID", required = true) Long codeId, @RequestBody PageUtil pageUtil) {
        return Result.success().data(codeUserChangeLogService.getList(codeId, pageUtil));
    }




}
